home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / misc / mf-db.zip / CSAMPLE\SPTEST\SPTEST.C < prev    next >
C/C++ Source or Header  |  1993-10-28  |  4KB  |  176 lines

  1. /*
  2.  
  3.     Quick example of SP functions in C
  4.  
  5. */
  6.  
  7.  
  8. #include <windows.h>
  9. #include "..\..\mf.h"
  10.  
  11.  
  12. typedef struct {
  13.     char name[20];
  14. } TEST_K0;
  15.  
  16. typedef struct {
  17.     char otherStuff[10];
  18. } TEST_DATA;
  19.  
  20. typedef struct {
  21.     TEST_K0        k0;
  22.     TEST_DATA    data;
  23. } TEST_REC;
  24.  
  25. int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  26. {
  27.     
  28.     hMF_TASK     mf_TASK;
  29.     hMF_DB        mf_TESTDB;
  30.     tmfExtDLL    mfExt;
  31.     
  32.     if (hPrevInstance)          /* Other instances of app running? Dont restart */
  33.         return(0);
  34.     if (lstrlen(lpCmdLine) == 0)
  35.         {
  36.         MessageBox(NULL, "Parameters: <DB_PATH> to store temp databases in \ne.g. C:\\ or c:\\test\\\n(backslash REQUIRED!)", "WARNING", MB_OK);
  37.         return (0);
  38.         }
  39.         
  40.         /*
  41.             mf_TASK is a global in abDB.h
  42.         */
  43.     mfExt.extType = -1;        /* No extensions */
  44.     mf_TASK = mfInit((ptmfExtDLL)&mfExt);
  45.     {
  46.     char     szdbPath[128];
  47.     int        idxSize[1];
  48.     int        idxType[1];
  49.     /* db to use */
  50.     lstrcpy(szdbPath, lpCmdLine);
  51.     lstrcat(szdbPath, "TESTDB");
  52.     
  53.     /* DB statistics */
  54.     idxSize[0]=sizeof(TEST_K0);
  55.     idxType[0]=MFCOMP_CHARIC;
  56.     if (mfCreateDB(szdbPath, sizeof(TEST_DATA), 1, idxSize, idxType) < 0)
  57.         {
  58.         MessageBox(NULL, "Create Failed", "ERROR", MB_OK);
  59.         return (-1);
  60.         }
  61.     
  62.     mf_TESTDB = mfOpen(szdbPath, mf_TASK);
  63.     if (mf_TESTDB < 0)
  64.         {
  65.         MessageBox(NULL, "Open database failed", "ERROR", MB_OK);
  66.         return (0);
  67.         }
  68.     }
  69.     /*
  70.         Create some data to read
  71.     */
  72.     {
  73.     TEST_REC    dbRecord;
  74.     int            n;
  75.     
  76.     lstrcpy((LPSTR)dbRecord.data.otherStuff, (LPSTR)"Whatever");
  77.     
  78.     /*
  79.         Create 60 alternating, yet repeated, identical items...
  80.         (This keeps the same items from being next to eachother (record # wise...)
  81.     */
  82.     for(n=0; n < 30; n++)
  83.         {
  84.         lstrcpy((LPSTR)dbRecord.k0.name, (LPSTR)"Brown");
  85.         mfWrite(mfAppendData((FPDATA)&dbRecord.data, mf_TASK, mf_TESTDB),
  86.                  (FPDATA)&dbRecord, 
  87.                  mf_TASK, 
  88.                  mf_TESTDB, 
  89.                  MFRW_ALL);
  90.         lstrcpy((LPSTR)dbRecord.k0.name, (LPSTR)"Smith");
  91.         mfWrite(mfAppendData((FPDATA)&dbRecord.data, mf_TASK, mf_TESTDB),
  92.                  (FPDATA)&dbRecord, 
  93.                  mf_TASK, 
  94.                  mf_TESTDB, 
  95.                  MFRW_ALL);
  96.         }
  97.     }
  98.     
  99.     /*
  100.     
  101.         Read a list...
  102.     */
  103.     {
  104.     #define    hits    6
  105.     RPTR    hitArray[hits];
  106.     long    hitCount;
  107.     char    display[256];
  108.     hitCount = mfReadList(  0,
  109.                             "Brown",
  110.                             5,
  111.                             &hitArray[0],
  112.                             hits,
  113.                             mf_TASK,
  114.                             mf_TESTDB,
  115.                             0);
  116.     wsprintf(display,
  117.             "Hits: %ld\nRecs:\n %ld\n %ld \n %ld\n %ld\n %ld",
  118.             hitCount,
  119.             hitArray[0],
  120.             hitArray[1],
  121.             hitArray[2],
  122.             hitArray[3],
  123.             hitArray[4]);
  124.     MessageBox(NULL, display, "Pass 1", MB_OK);
  125.     
  126.     /*
  127.         Contiune to read...
  128.         NOTE:
  129.         We made the hitArray ONE bigger than we want.  This allows us to
  130.         pre-seed the next hit into the system.
  131.         We only use the first 5 of the records...  This will also work on the
  132.         LAST record (e.g. if there are 6 final matches) because it
  133.         will automatically wrap the loop 1 more time to pick up the final record...
  134.     */
  135.     while(hitCount == hits)
  136.         {
  137.         hitCount = mfReadList(  hitArray[5],
  138.                                 "Brown",
  139.                                 5,
  140.                                 &hitArray[0],
  141.                                 hits,
  142.                                 mf_TASK,
  143.                                 mf_TESTDB,
  144.                                 0);
  145.         /*
  146.             This may not be politically correct, however,
  147.             this is a demo.  Obviously, if there are only
  148.             3 matches, it will print more than there really are.
  149.             
  150.             Oh well...
  151.         */
  152.         wsprintf(display,
  153.                 "Hits: %ld\nRecs:\n %ld\n %ld \n %ld\n %ld\n %ld",
  154.                 hitCount,
  155.                 hitArray[0],
  156.                 hitArray[1],
  157.                 hitArray[2],
  158.                 hitArray[3],
  159.                 hitArray[4]);
  160.         MessageBox(NULL, display, "More Passes", MB_OK);
  161.         
  162.         }
  163.         
  164.                             
  165.     
  166.     }
  167.     
  168.     
  169.     /*
  170.         Closes all DB's and deallocs stuff
  171.     */
  172.     mfDeInit(mf_TASK);
  173.     
  174.     return (0);
  175. }
  176.